package org.csu.mypetstore.domain;

import java.math.BigDecimal;

public class CartItem {
    private Item item;
    private int stockQuantity;
    private int cartQuantity;
    private boolean inStock;
    private BigDecimal total;

    public Item getItem() {
        return item;
    }


    public int getCartQuantity() {
        return cartQuantity;
    }

    public void setCartQuantity( int cartQuantity ) {
        this.cartQuantity = cartQuantity;
        calculateTotal();
    }

    public boolean isInStock() {
        return inStock;
    }

    public void setInStock( boolean inStock ) {
        this.inStock = inStock;
    }

    public BigDecimal getTotal() {
        return total;
    }

    public void setTotal( BigDecimal total ) {
        this.total = total;
    }


    public void setItem( Item item ) {
        this.item = item;
        calculateTotal();
    }

    public int getStockQuantity() {
        return stockQuantity;
    }

    public void setStockQuantity( int stockQuantity ) {
        this.stockQuantity = stockQuantity;
    }

    public void incrementCartQuantity() {
        cartQuantity ++;
        calculateTotal();
    }

    private void calculateTotal() {
        if ( item != null && item.getListPrice() != null ) {
            total = item.getListPrice().multiply( new BigDecimal( cartQuantity ) );
        } else {
            total = null;
        }
    }

}
